﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using AvatarHelper;
using Avatar.Model;
using AvatarDAL;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

/// <summary>
///AvatarDataService 的摘要说明
/// </summary>
[WebService(Namespace = "http://jobs.bd365.net/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。 
// [System.Web.Script.Services.ScriptService]
public class AvatarDataService : System.Web.Services.WebService
{
    protected string _strConn = ConfigurationManager.ConnectionStrings["AvatarConnectionString"].ConnectionString;

    [WebMethod]
    public DataSet GetDataBySQL(string _sqlStr)
    {
        using (SqlConnection _conn = new SqlConnection(_strConn))
        {
            DataSet _ds = new DataSet();
            SqlDataAdapter _ad = new SqlDataAdapter(_sqlStr, _conn);
            _ad.Fill(_ds);
            return _ds;
        }
    }

    [WebMethod]
    public int RunSql(string _sqlStr)
    {
        using (SqlConnection _conn = new SqlConnection(_strConn))
        {
            SqlCommand _ds = new SqlCommand(_sqlStr, _conn);
            _conn.Open();
            int _i= _ds.ExecuteNonQuery();
            _conn.Close();
            return _i;
        }
    }

    //[WebMethod]
    //public List<T> GetALL<T>() where T : class
    //{
    //    List<T> _list = new List<T>();

    //    using (var _sdc = GetDataContext())
    //    {
    //        _list = _sdc.GetTable<T>().ToList();
    //    }

    //    return _list;
    //}

    //[WebMethod]
    //public static bool InsertALL<T>(List<T> _object, Func<T, bool> _duplication) where T : class
    //{
    //    bool _ok = false;
    //    using (var _sdc = GetDataContext())
    //    {
    //        var _b = _sdc.GetTable<T>().Where(_duplication).FirstOrDefault();
    //        if (_b == null)
    //        {
    //            _sdc.GetTable<T>().InsertAllOnSubmit(_object);

    //            _sdc.SubmitChanges();

    //            _ok = true;
    //        }
    //        else
    //        {
    //            throw new Exception("不能重复添加对象");
    //        }
    //    }
    //    return _ok;
    //}

}

